package com.sjtu.rest;

import com.sjtu.zookeeper.InstanceDetails;
import com.sjtu.zookeeper.ServiceDiscoverUtil;
import org.apache.curator.x.discovery.ServiceInstance;
import org.apache.curator.x.discovery.ServiceProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * nerine
 * 2/5/2020
 */
@RestController
public class HelloRest {

    @GetMapping("/test/hello")
    public String hello() throws Exception {
        ServiceProvider<InstanceDetails> provider = ServiceDiscoverUtil.getServiceProvider("SERVER-CORE");

        ServiceInstance<InstanceDetails> instance = provider.getInstance();

        System.out.println("http://" + instance.getAddress() + ":" + instance.getPort());

        return "hello, this is demo client";
    }
}
